Skip to content

perf(web): split heavy chat chunks and group startup bundles - #1096

Merged
badcuban merged 9 commits into
mainfrom
perf/split-chat-web-chunks
Nov 25, 2026
Merged

badcuban merged 9 commits into
mainfrom
perf/split-chat-web-chunks

Conversation

@badcuban

Copy link
Copy Markdown
Collaborator

Stacked on #1095.

Opening a chat thread eagerly downloaded and parsed 198 static JS files (5,723 KB raw, 1,814 KB gzipped), including @pierre/diffs, the VS Code file icon catalog, the GitHub HTML sanitizer, and closed-by-default panels and dialogs. App startup alone also loaded 96 separate files with 70 small chunks under 5 KB.

What changed

  • Decoupled @pierre/diffs (447 KB) from chat startup, queued custom code theme registrations until Pierre loads, cleared rejected import promises so transient failures recover, and gated highlighter warm-up on fenced code blocks so prose-only chats skip loading it.
  • Moved the VS Code file icon catalog (278 KB) behind an on-demand loader with same-size generic icon fallbacks and online retry recovery.
  • Split the GitHub HTML markdown sanitizer (159 KB) out of standard chat markdown and folded message previews, suppressing raw HTML fallback text while the sanitizer chunk loads.
  • Split Find in chat indexing out of initial chat load while keeping the Find bar input, focus capture, and Escape handling eager so Cmd/Ctrl+F never leaks keystrokes into the composer.
  • Lazy-loaded closed-by-default side panels and dialogs (Source Control, Agents, Project Board, Browser preview, Theme Picker, PR Thread dialog, File Preview dialog, and scheduled task timeline rows), preserving Escape cancellation during load and reserving row height for schedule lines.
  • Added zero-leakage Rolldown codeSplitting groups in apps/web/vite.config.ts for initial React, Effect, TanStack, UI, contracts, and shared startup modules.
  • Updated one assertion in apps/web/src/components/ChatView.panels.browser.tsx to wait for the lazy Source Control panel body after clicking its tab, matching the existing waits in the same test.

Before and after bundle size

Measured from production builds of chore/perf-apps-performance-audit versus this branch by tracing the exact static JS import graph for each screen.

Screen Before After Change
App startup 96 files, 2,601 KB raw (835 KB gzipped) 8 files, 2,636 KB raw (806 KB gzipped) 92% fewer files, -29 KB gzipped
Opening a chat thread 198 files, 5,723 KB raw (1,814 KB gzipped) 109 files, 4,780 KB raw (1,514 KB gzipped) -942 KB raw (-16.5%), -300 KB gzipped (-16.5%), 45% fewer files
Opening a new draft 193 files, 5,609 KB raw (1,776 KB gzipped) 106 files, 4,751 KB raw (1,503 KB gzipped) -859 KB raw (-15.3%), -273 KB gzipped (-15.4%), 45% fewer files
Opening Settings 182 files, 3,434 KB raw (1,135 KB gzipped) 99 files, 3,463 KB raw (1,104 KB gzipped) 46% fewer files, -31 KB gzipped

Verification

  • vp fmt, vp lint, and vp run typecheck (14/14 packages)
  • vp run --cache '@threadlines/web#test' (273 test files, 3,408 tests)
  • vp run --cache '@threadlines/web#test:browser' (118 test files, 1,215 tests)
  • vp run '@threadlines/web#build'

High-rate streaming deltas, session sweeps, and projection writes were triggering redundant SQLite reads, full-row JSON rewrites, and repeated full read-model hydrations on the main thread.

- Return early in ProviderService.listSessions when no adapters are active and fetch bindings only for active session thread IDs.
- Route content.delta runtime ingestion through a narrow active-thread lookup (session and live side-turns) instead of four-query shell hydration with diff-stat rollups.
- Update only updated_at in ProjectionPipeline for assistant messages and activities, guard subagent roster reads behind activityMayAffectSubagents, skip streaming session lookups and no-op turn upserts, and drop redundant correlated subqueries from message upserts.
- Guard Claude partial tool JSON decoding with outer-brace checks, enforce the 500 ms file-change estimate throttle before scanning, and scan partial JSON strings in linear-time slices.
- Scope shell snapshot diff-stat rollups to active or archived threads and replace non-engine getCommandReadModel calls in ProjectSetupSource, LinkMoves, and single-thread ThreadMoves paths.
- Drop six unused or prefix-redundant SQLite indexes in migration 126 and tune NodeSqliteClient with a 1024-entry statement cache, borrower-based statement execution, prepared transaction controls, and savepoint release.
- Wake AssistantEvents discovery only on events that produce assistant actions, and nudge discovery on stale settlements.
Streaming turns and composer typing triggered redundant markdown parses, full-thread UI syncs, duplicated inbox derivations, and broad store re-renders in the web client, while the desktop app serialized shell probing ahead of startup, rasterized all 38 macOS tray icons upfront, and kept preview browser CDP buffers and accessibility active.

Stabilize markdown link-kind state, cache per-block file-path scans, narrow backdrop observers on active chat threads, deduplicate thread shells structurally on modelSelection, switch thread upserts to single-thread UI sync, share one inbox derivation with narrower component selectors, overlap desktop shell probing with startup, rasterize macOS tray frames lazily on first use, and disable unused preview CDP response buffering and eager accessibility tracking.
…s async

Reduces checkpoint git overhead, WebSocket fanout work, retained evicted thread memory, idle reveal animation frames, and blocking main-thread log and cache writes.

- Coordinate pre-turn checkpoints across ProviderCommandReactor and CheckpointReactor, shard checkpoint work across threads with per-checkout revert serialization, and cache stable git lookups in scratchIndex.
- Share one coalesced shell stream producer across WebSocket clients, bound shell and thread subscriber queues with clean resync on overflow, and return only the sequence on event store appends.
- Release evicted thread detail slices and derivation caches while pausing idle eviction offline and preserving pending scroll anchors and worktree locks.
- Create streaming text reveal observers lazily, stop idle animation frames when caught up, and advance only the live reveal tail.
- Move rotating trace and provider logs to fs.promises with per-path rotation locks and shutdown flush, batch desktop child logs, optimize terminal ANSI scans and output bursts, compact usage rate caches, and debounce usage scan cache writes.
Reduces background polling, process spawns, memory retention, and hot-path work across server, web, desktop, shared, and client-runtime without changing user-visible behavior.

- Relay: pass fixed ArrayBuffer views directly to WebCrypto, build header-prefixed records in one allocation, and avoid double-copying single-part frames.
- Providers: slow disabled provider scheduled refreshes by 6x, cap refreshAll concurrency to 3, cache scheduled Claude token usage within the same UTC day, and cache claude --version by resolved executable stat metadata.
- Git and workspace: skip numstat diffs on clean status checks, reuse status GitConfigSnapshot in GitManager, cap background remote refreshes to 4 with post-permit re-checks, and filter ignored tracked files via git ls-files --cached --ignored.
- Pull requests: raise viewer and repository cache capacities to 64, run authored searches in parallel with workspace listings, share worktree listings per sweep with fresh revalidation before auto-merge, and back off confirmed missing worktrees.
- Server and client cleanups: cache ProjectFaviconResolver lookups, stop retaining raw SDK messages in ClaudeAdapter turnState.items, tag OpenCode and ACP streaming chunks as stream fragments, cache compiled search regexes, track MJPEG scan cursors, replace Equal.equals on work rows, skip redundant activity sorts, lazy-load DiffWorkerPoolProvider, pause the desktop backdrop CPU watchdog when art is still or hidden, and cache mainFrameId in PreviewAutomation.
Opening a chat thread eagerly downloaded and parsed 198 static JS files (5,723 KB raw, 1,814 KB gzipped), including `@pierre/diffs`, the VS Code file icon catalog, the GitHub HTML sanitizer, and panels and dialogs that start closed. Startup alone also pulled 96 separate files with 70 small chunks under 5 KB.

This splits those features behind on-demand imports and groups stable initial libraries in Vite/Rolldown without pulling lazy code into startup:

- Decouple `@pierre/diffs` from initial chat load, queue custom theme registrations until Pierre loads, recover from failed imports, and gate highlighter warm-up on fenced code blocks.
- Load the VS Code file icon manifest on demand with a same-size fallback icon and reconnect retry.
- Load the GitHub HTML markdown renderer only for GitHub HTML documents, and keep Find in chat indexing lazy while keeping the Find bar input, focus capture, and Escape handling eager.
- Lazy-load closed-by-default side panels, dialogs, the theme picker, and scheduled task timeline lines, preserving Escape cancellation while chunks load and reserving row height for schedule lines.
- Group initial React, Effect, TanStack, UI, contracts, and shared startup code in `apps/web/vite.config.ts`.

This cuts initial chat thread JS by 942 KB raw (300 KB gzipped, -16.5%) and 45% fewer files, and drops app startup from 96 files to 8 files (-29 KB gzipped).
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
threadlines Skipped Skipped Nov 25, 2026 6:31am UTC

Request Review

Wait for RotatingFileSink.writeAsync to settle and for the flush fiber to reschedule before advancing TestClock in packages/shared/src/observability.test.ts, preventing the CI timeout race when async fs.promises calls finish after the test probe triggers.

Group initial vendor and shared startup modules in apps/web/vite.config.ts using $initial and entriesAware rules so startup drops from 96 JS files to 8 files and stays 30 KB under the 915 KB gzip budget.
…-web-chunks

# Conflicts:
#	apps/web/src/components/ChatView.tsx
Base automatically changed from chore/perf-apps-performance-audit to main November 25, 2026 06:31
…hunks

# Conflicts:
#	apps/web/src/components/ChatMarkdown.tsx
@badcuban
badcuban added this pull request to the merge queue Nov 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 25, 2026
@badcuban
badcuban added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 3c8880d Nov 25, 2026
25 checks passed
@badcuban
badcuban deleted the perf/split-chat-web-chunks branch November 25, 2026 06:57

This branch was previously deployed

1 inactive deployment
Preview — dd052f95 Deployed Nov 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant